// Copyright (C) joyinter
// All rights reserved.
// 
// Author : Jiang Li
// Date   : 2004-12-29

#include "stdafx.h"
#include "tm_updateroom.h"
#include <common/svr_base/svr_asyncqueue.h>
#include <common/svr_base/db_utility.h>
#include "msvr_server.h"
#include "async_updateroom.h"

namespace JoyServer
{

// class CJoyTmUpdateRoom

CJoyTmUpdateRoom::CJoyTmUpdateRoom()
{
    m_server    = NULL;
    m_asyncQueue= NULL;
}

CJoyTmUpdateRoom::~CJoyTmUpdateRoom()
{
}

bool CJoyTmUpdateRoom::Create(CJoyMainServer* pServer)
{
    m_server    = pServer;

    m_asyncQueue = new CJoyAsyncQueue();
    if(!m_asyncQueue->Create(pServer->m_asyncExec))
    {
        return false;
    }

    DWORD dwElapse = 30000;
    pServer->FindTiming("update_room", dwElapse);

    if(!__super::Create(&pServer->m_timer, dwElapse))
    {
        return false;
    }
    return true;
}

void CJoyTmUpdateRoom::Destroy()
{
    __super::Destroy();

    if(m_asyncQueue != NULL)
    {
        m_asyncQueue->Destroy();
        m_asyncQueue->Release();
        m_asyncQueue = NULL;
    }
}

void CJoyTmUpdateRoom::OnExecute()
{
    if(m_asyncQueue->IsEmpty())
    {
        CJoyAsyncUpdateRoom* asyncUpdate = new CJoyAsyncUpdateRoom(this);
        m_asyncQueue->QueueObject(asyncUpdate);
    }
}

} // namespace JoyServer